﻿@{
    ViewBag.Title = "欢迎使用" + Admin.MvcApplication.SystemName + "，请登录！";
    Layout = "~/Views/Shared/_LoginLayout.cshtml";
}
<script type="text/javascript">

    $(document).ready(function () {

        $.validator.setDefaults({
            errorElement: "div",
            errorClass: "tip",
            errorPlacement: function (error, element) {
                error.appendTo(element.parent())
            }
        });

        $("#account").focus();

        //表单验证 
          var v =  $("#aspnetForm").validate({
            focusInvalid:true,
            rules: {
                account: { required: true },
                password: { required: true }
            },
            messages: {
                account: {
                    required: "请输入帐号！"
                },
                password: {
                    required: "请输入密码！"
                }
            }
        });

        $("#btnLogin").unbind("click");
        $("#btnLogin").click(function () {
            if (!$("#aspnetForm").valid())
                return false;

            LoginError("登录中","317EC8");

            $.ajax({
                url: $('#aspnetForm').attr("action"),
                data: $('#aspnetForm').serialize(),
                type: "Post",
                error: function (request) {
                LoginError("登陆出现未知错误，请重试！","red");
                return false;
                },
                success: function (e) {
                //结果[0:失败， 1:成功， 2:帐号密码不正确， 3:用户已禁用]
                    //$("#alertInfo").hide();
                    if (e == 1) {
                        LoginError("登录成功，正在跳转页面","317EC8");
                        var returnUrl = "@Request.QueryString["ReturnUrl"]";
                        if (returnUrl == "")
                            returnUrl = "@Url.Action("Index", "Home")";
                        self.location =returnUrl;
                    }
                    else {
                        //出错处理
                LoginError("登录失败，帐号/密码错！");
                    }
                return false;
                }
            });
                return false;
        });
    });


//呈现出错信息
function LoginError(errorMessage, color) {
    $("#alertInfo").text(errorMessage);
    if (color != undefined) {
        $("#alertInfo").css("color","#" + color);
    }
    else {
        $("#alertInfo").css("color","red");
    }
}

</script>
<h3 id="alertInfo">
    请您输入帐号密码，登录本系统 ...
</h3>
<form id="aspnetForm" action="@Url.Action("Valid")" name="aspnetForm" method="post">
    <div class="">
        <p>
            <label for="account">
                帐号：
            </label>
            @Html.TextBox("account", "", new { tabindex = "1", style = "width:160px" })
        </p>
        <p>
            <label for="password">
                密码：
            </label>
            @Html.Password("password", "", new { tabindex = "2", style = "width:160px" })
        </p>
        <p id="trVerify" style="display: none;">
            <label for="txtVerify">
                验证码：
            </label>
            @Html.TextBox("verify", "", new { tabindex = "3", style = "width:90px" })
        </p>
        <p class="op">
            <input type="submit" id="btnLogin" value="登录" tabindex="7" />
            <input type="checkbox" id="chkAutoLogin" value="true" tabindex="6" name="autoLogin" /><label for="chkAutoLogin">
                自动登录
            </label>
        </p>
    </div>
</form>
